package com.lihao.wanandroid.ui.login

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.lihao.jetpackcore.base.BaseViewModel
import com.lihao.jetpackcore.ext.request
import com.lihao.jetpackcore.state.ResultState
import com.lihao.wanandroid.data.AppRepository
import com.lihao.wanandroid.data.model.UserInfoResponse

/**
 * 登陆
 */
class LoginRegisterViewModel(application: Application) : BaseViewModel(application) {

    var username: String = ""

    var password: String = ""

    var repassword: String = ""

    val userInfo: MutableLiveData<ResultState<UserInfoResponse>> = MutableLiveData()

    val registerResult: MutableLiveData<ResultState<Any>> = MutableLiveData()

    fun login() {
        request({
            AppRepository.login(username, password)
        }, userInfo, true, "登陆中...")
    }

    fun register() {
        request({
            AppRepository.register(username, password, repassword)
        }, registerResult)
    }


}